package com.bruce.ai.function.service;

import com.bruce.ai.services.FlightBookingService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Description;
import org.springframework.core.NestedExceptionUtils;
import org.springframework.stereotype.Service;
import com.bruce.ai.function.info.BookingDetailFunctionInfo;

import java.util.function.Function;

@Service
public class BookingDetailFunctionService {

    private static final Logger logger = LoggerFactory.getLogger(BookingDetailFunctionService.class) ;

    @Autowired
    private FlightBookingService flightBookingService;



    @Bean
    @Description("获取机票预定详细信息")
    public Function<BookingDetailFunctionInfo.BookingDetailsRequest, BookingDetailFunctionInfo.BookingDetails> getBookingDetails() {
        return request -> {
            try {
                return flightBookingService.getBookingDetails(request.bookingNumber(), request.name());
            }
            catch (Exception e) {
                logger.warn("Booking details: {}", NestedExceptionUtils.getMostSpecificCause(e).getMessage());
                return new BookingDetailFunctionInfo.BookingDetails(request.bookingNumber(), request.name(), null, null, null, null, null);
            }
        };
    }
}
